package com.kehongborui.fliggy.controller;

import com.kehongborui.fliggy.entity.User;
import com.kehongborui.fliggy.enums.LOGIN_USER;
import com.kehongborui.fliggy.model.OrderModel;
import com.kehongborui.fliggy.model.ResultModel;
import com.kehongborui.fliggy.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhang peng yang ming
 * @CopyRight (C) http://www.csdn.com
 * @brief 订单
 * @email 122162005@qq.com
 * @date 2018-08-29
 */
@RestController
@RequestMapping("/train/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping
    public ResultModel create(@RequestBody OrderModel orderModel, HttpServletRequest request) {
        orderModel.setBuyerUid(((User)request.getSession().getAttribute(LOGIN_USER.USER.name())).getUid());
        OrderModel model = orderService.create(orderModel);
        // 订单创建成功后返回确认订单页面
        return ResultModel.OK("/confirm_order?orderid=" + model.getOrderId());
    }
}
